<template>
  <div  class="gk-layout-container"  >
		<div  class="gk-layout-header"  >
			<s-query perms="core:coreStock"   @click="findPage" add=true  @addClick="handleAdd" >
				<el-form-item>
					<el-input v-model="filters.name" placeholder="物料名称"></el-input>
				</el-form-item>
			</s-query>
		</div>
		<div class="gk-layout-main">
		<my-table :data="pageResult.content"  :loading="loading" >
			<el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
				<template slot-scope="scope">   {{scope.$index+1}}   </template>
			</el-table-column> 
			<Column   prop="boxCode" label="条码"  />
			<Column   prop="locId" label="库位"  />
			<Column   prop="detCount" label="记录数"  />
			<Column   prop="status" label="状态" :formatter="selectionFormat"    />
			<Column   prop="createTime" label="创建时间" :formatter="dateFormat"    />
			<el-table-column  header-align="center"  align="center" width="300"    :label="$t('action.operation')" >
				<template slot-scope="scope">
					<kt-button   :disabled="scope.row.detCount!=0"     :label="$t('action.edit')"  perms="core:StocktIn:edit" :size="global.gSize"   @click="handleEdit(scope.$index, scope.row)" />
					<kt-delete-button    :disabled="scope.row.detCount!=0"    perms="core:StocktIn:edit"    @click="handleDelete(scope.$index, scope.row)" />
				</template>
			</el-table-column>
		</My-table>
		</div>
		<!--分页栏-->
		<div class="toolbar gk-layout-footer"  style="padding:10px;"> 
			<el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
						:current-page="filters.pageNum"
						:page-size="filters.pageSize"
						:total="pageResult.totalSize"
						style="float:right;">
			</el-pagination>
		</div>

		<core-stock-edit    :dialogVisible="editDialogVisible1"  :row=selectStock  @stockViewHidden="stockViewHidden"></core-stock-edit>
  </div>
</template>

<script>

import KtButton from "@/views/Core/KtButton"
import MyTable from "@/views/Core/MyTable"
import Column from "@/views/Core/Column"
import { format,formatDay } from "@/utils/datetime"
import {  dictsFormat ,getItemName} from "@/utils/myUtil"
import CoreStockEdit from "@/dialog/CoreStockEdit"
import SQuery from "@/components/Kj/SQuery"
	import KtDeleteButton from "@/views/Core/KtDeleteButton"
import { validatorNumber } from "@/utils/validate"
 
export default {
	components:{
		MyTable,
		KtButton,
		Column,
		CoreStockEdit,
		KtDeleteButton,
		SQuery
	},
	data() { 
		return { 
	 		timer:new Date().getTime() , //声明timer 
			filters: {
				 pageNum: 1, pageSize: this.global.pageSize
			},  
			deleteIds:[],
			loading: false,
		 
			pageResult: {},
		 
			selectStock: {}, 
			editLoading: false,	
		    editDialogVisible1:false,
			dataFormRules: {
                    barCode: [{ required: true, trigger: 'blur' , message: "请输入条码"}],
					countDb: [{ required: true, trigger: 'blur',validator: validatorNumber }]
            },
		}
	},
	methods: {
		stockViewHidden:function(){
			this.editDialogVisible1= false
			this.findPage();
		},
	  
		// 获取分页数据
		findPage: function (data) {
		if(data!=-1){
			data=data||1
			this.filters.pageNum=data
		 
		}
		 
			this.filters.playType=1
			this.$api.coreStock.findPage(this.filters).then((res) => {
				this.pageResult = res.data
			})
		},				
	    // 显示编辑界面
		handleEdit: function (params,row) {
			this.editDialogVisible1= true
			this.selectStock = Object.assign({}, row) 
		}, 
		handleDelete: function (params,row) {
			this.rowDataForm = Object.assign({},  row);
			this.editLoading = true
			this.$api.coreStock.deleteStock(this.rowDataForm).then((res) => {
				//this.editLoading = false
				if (res.code == 200) {
				this.$message({ message: this.$t('action.operateSucess'), type: 'success' })
				} else {
				this.$message({ message: this.$t('action.operateFail') + res.msg, type: 'error' })
				}
				this.findPage(-1)
			})
		},
		handleAdd: function () {
			this.editDialogVisible1= true
			this.selectStock={status:2};
		}, 
		// 时间格式化
      	dateFormat: function (row, column, cellValue, index){
          	return format(row[column.property])
      	},	
		// 时间格式化
		selectionFormat: function (row, column, cellValue, index){ 
			let key=""
			let propt=column.property;
			if(propt=="status"){
				key="stockStatus"
			}else if (propt == "storeStatus") {
				key = "storeStatus"
			} else if(propt=="locked"){
				key="isLocked"
			}
	  
          	return dictsFormat( key,cellValue)
      	}
	},
	 created () { 
    },
	mounted(){
		 this.findPage(1)
	}
}
</script>

<style scoped>

</style>